<?

if (strstr($cfg['sslang'],",")) $sslang = explode(",",$cfg['sslang']);

else $sslang[0] = $cfg['sslang'];



if (isset($action) && $userdata['type'] != "demo" && $confirm) {

switch ($action) {

	case "add":

		foreach($sslang as $val) {

			if ($data['serverside'][$val] == "") { $data['serverside'][$val] = "off"; }

			$serverside .= $data['serverside'][$val].",";

		}

		$serverside = substr($serverside,0,strlen($serverside)-1);

		if ($data['shell'] == "") { $data['shell'] = "off"; }

		$SQL = "INSERT INTO packages(name, pointers, subdomains, users, hd, transfer, bandwidth, serverside, `databases`, mm, shell, ownerid)

				VALUES('".addslashes($data['name'])."', ".$data['pointers'].", ".$data['subdomains'].", ".$data['users'].", ".$data['hd'].", ".$data['transfer'].", ".$data['bandwidth'].", '".$serverside."', ".$data['databases'].", ".$data['mailinglists'].", '".$data['shell']."', '".$resellerdata['id']."')";

		if (mysql_query($SQL)) {

			$result = $T['Package added.'];

		} else {

			$error = $T['Could not add package.'];

		}

		break;

		

	case "remove":

		$SQL = "DELETE FROM packages WHERE ownerid = '".$resellerdata['id']."' AND id = ".$data[id];

		if (mysql_query($SQL)) {

			$result = $T['Package removed.'];

		} else {

			$error = $T['Could not remove package.'];

		}

		break;

}

} elseif (isset($action) && $userdata['type'] == 'demo') {

	echo "<center>".$T['err']['demo user']."</center>";

} elseif (isset($action) && !$confirm) {

?>

<blockquote>

<form action="<?=$current_url;?>" method="post" name="webcp1" onSubmit="submitonce(this);">



&nbsp;&nbsp; <?=$T['Really '.$action];?><b>&nbsp;<?=$data['name'];?>?</b><br>

&nbsp;&nbsp;&nbsp;<input type="submit" value="<?=$T['yes'];?>">

<?



foreach ($data as $key => $val) {

	if (is_array($data[$key])) {

		foreach ($data[$key] as $key2 => $val2) {

			echo '<input type="hidden" name="data['.$key.']['.$key2.']" value="'.$val2.'">';

		}

	} else {

		echo '<input type="hidden" name="data['.$key.']" value="'.$val.'">';

	}

}

?>

<input type="hidden" name="action" value="<?=$action;?>">

<input type="hidden" name="confirm" value="true">

</form>

</blockquote>

<?

}



$SQL = "SELECT id, name, description, pointers, subdomains, users, hd, transfer, bandwidth, serverside, `databases`, mm as mailinglists, shell FROM packages WHERE ownerid = '".$resellerdata['id']."'";

$packagelist = mysql_query($SQL);



if ($error)

	echo "<br>&nbsp;&nbsp; ".$error."<br><br>\n";

if ($result) 

	echo "<br>&nbsp;&nbsp; ".$result."<br><br>\n";



if (mysql_num_rows($packagelist)) {



?>

<div align="center" style='margin-left: 5px;'>

<table border="0" cellspacing="0" cellpadding="0" class="tblbg">

	<tr>

		<td>

		<table border="0" cellspacing="1">

			<tr>

				<td colspan="20" class="tbltop">&nbsp;<?=$T['menu'][$url];?>&nbsp;</td>

			</tr>

			<tr class="row1">

				<td align=center><?=$T['Name'];?></td>

				<td align=center><?=$T['Users'];?></td>

				<td align=center><?=$T['HD'];?></td>

				<td align=center><?=$T['Transfer'];?></td>

				<? if ($cfg['bandwidth']) { ?>

					<td align=center><?=$T['Bandwidth'];?></td>

				<? } ?>

				<td align=center><?=$T['Subdomains'];?></td>

				<td align=center><?=$T['Pointers'];?></td>

				<td align=center><?=$T['Databases'];?></td>

				<? if ($cfg['maillist'] == 'mailman') { ?>

				<td align=center><?=$T['Mailing Lists'];?></td>

				<? } ?>

				<?

				foreach($sslang as $val) {

					echo "<td align=center>$val</td>";

				}

				?>

				<td align=center><?=$T['Shell'];?></td>

				<td align=center><?=$T['Add Site'];?></td>

				<td align=center><?=$T['Del Pkg'];?></td>

			</tr>

			<?

			for ($i=0; $p=mysql_fetch_array($packagelist); $i++) {

				$rowclass = ($i % 2) ? "row1" : "row2";

				echo "<tr class='$rowclass'>";

				echo "<td>".$p['name']."</td>";

				echo "<td align=center>".(($p['users'] != -1) ? $p['users'] : $T['Unlim'])."</td>";

				echo "<td align=center>".(($p['hd'] != -1) ? (($p['hd'] > 1024) ? round(($p['hd']/1024),2)."GB" : $p['hd']."MB") : $T['Unlim'])."</td>";

				echo "<td align=center>".(($p['transfer'] != -1) ? $p['transfer']."GB" : $T['Unlim'])."</td>";

				if ($cfg['bandwidth']) {

					echo "<td align=center>".(($p['bandwidth'] != 0) ? $p['bandwidth'].$T['KB/s'] : $T['Unlim'])."</td>";

				}

				echo "<td align=center>".(($p['subdomains'] != -1) ? $p['subdomains'] : $T['Unlim'])."</td>";

				echo "<td align=center>".(($p['pointers'] != -1) ? $p['pointers'] : $T['Unlim'])."</td>";

				echo "<td align=center>".(($p['databases'] != -1) ? $p['databases'] : $T['Unlim'])."</td>";

				if ($cfg['maillist'] == 'mailman') {

					echo "<td align=center>".(($p['mailinglists'] != -1) ? $p['mailinglists'] : $T['Unlim'])."</td>";

				}

				$sslangarray = explode(",", $p['serverside']);

				unset($p['serverside']);

				for ($i=0; $i<sizeOf($sslang); $i++) {

					$p['serverside'][trim($sslang[$i])] = $sslangarray[$i];

				}

				foreach($p['serverside'] as $key => $val) {

					echo "<td align=center><img src='icon/";

					switch($val) {

						case "on":

							echo "check";

							break;

						case "off":

							echo "x";

							break;

						case "na":

							echo "na";

							break;

					}

					echo ".gif'></td>";

				}

				echo "<td align=center><img src='icon/";

				switch($p['shell']) {

					case "on":

						echo "check";

						break;

					case "off":

						echo "x";

						break;

					case "na":

						echo "na";

						break;

				}

				echo ".gif'></td>";

				echo "<td align=center><a href='?url=newdomain&number=".$resellerdata['id']."&cp=reseller&package=".$p['id']."'><img src='icon/plus.gif' border=0 height=16 width=16></a></td>";

				echo "<td align=center><a href='$current_url&action=remove&data[id]=".$p['id']."&data[name]=".$p['name']."'><img src='icon/remove.gif' border=0></a></td>";

				echo "</tr>";

			}

			?>

		</table>

		</td>

	</tr>

</table>

</div>

<br>

<? } ?>

<div align="center">

<form action='<?=$current_url;?>' method='post'>

<input type=hidden name=action value="add">

<table border="0" cellspacing="0" cellpadding="0" class="tblbg">

	<tr>

		<td>

		<table border="0" cellspacing="1">

			<tr>

				<td colspan="20" class="tbltop">&nbsp;<?=$T['Add a Package'];?>&nbsp;</td>

			</tr>

			<?

				echo "<tr><td class='row1'><B>&nbsp;".$T['Package Name']."&nbsp;</B></td><td class='row2'><input type=textbox size=20 name=data[name] value='".$p['name']."'></td></tr>";

				echo "<tr><td class='row1'><B>&nbsp;".$T['Users']."&nbsp;</B></td>";

				?>

				<td class="row2">&nbsp;<input type="text" name="data[users]" size="5" maxlength="255" value="<? if ($p['users'] != -1) if(isset($p['users'])) echo intval($p['users']); else echo '';?>" id="users" onchange="document.getElementById('usercheck').checked = false;">&nbsp;<input type=checkbox id="usercheck" name="data[users]" value="-1" onclick="document.getElementById('users').value = '';" <? if ($p['users'] == -1) echo "checked";?><?if ($resellerdata['users'] != -1) echo " disabled";?>><?=$T['Unlimited'];?></td></tr>

				<?

				echo "<tr><td class='row1'><B>&nbsp;".$T['HD Space']."&nbsp;</B></td>";?>

				<td class="row2">&nbsp;<input type="text" name="data[hd]" size="5" maxlength="255" value="<? if ($p['hd'] != -1) if(isset($p['hd'])) echo intval($p['hd']); else echo '';?>" id="hd" onchange="document.getElementById('hdcheck').checked = false;"> <?=$T['mb'];?>&nbsp;<input type=checkbox id="hdcheck" name="data[hd]" value="-1" onclick="document.getElementById('hd').value = '';" <? if ($p['hd'] == -1) echo "checked";?><?if ($resellerdata['hd'] != -1) echo " disabled";?>><?=$T['Unlimited'];?></td>

				<?

				echo "<tr><td class='row1'><B>&nbsp;".$T['Transfer']."&nbsp;</B></td>";?>

				<td class="row2">&nbsp;<input type="text" name="data[transfer]" size="5" maxlength="255" value="<? if(isset($p['transfer'])) echo intval($p['transfer']); else echo '';?>" id="transfer" onchange="document.getElementById('transfercheck').checked = false;"> <?=$T['gb'];?>&nbsp;<input type=checkbox id="transfercheck" name="data[transfer]" value="-1" onclick="document.getElementById('transfer').value = '';" <? if ($p['transfer'] == -1) echo "checked";?><?if ($resellerdata['transfer'] != -1) echo " disabled";?>><?=$T['Unlimited'];?></td>

				<?

				if ($cfg['bandwidth']) { 

					echo "<tr><td class='row1'><B>&nbsp;".$T['Bandwidth']."&nbsp;</B></td>";?>

					<td class="row2">&nbsp;<input type="text" name="data[bandwidth]" size="5" maxlength="255" value="<? if ($p['bandwidth'] != 0) if($p['bandwidth']) echo intval($p['bandwidth']); else echo '';?>"  id="bandwidth" onchange="document.getElementById('bandwidthcheck').checked = false;">&nbsp;<?=$T['KB/s'];?>&nbsp;<input type=checkbox id="bandwidthcheck" name="data[bandwidth]" value="0" onclick="document.getElementById('bandwidth').value = '';" <? if ($resellerdata['bandwidth'] == 0) echo "checked";?><?if ($resellerdata['bandwidth'] != 0) echo " disabled";?>><?=$T['Unlimited'];?></td>

					<?

				} else {
					echo '<input type=hidden id="bandwidthcheck" name="data[bandwidth]" value="0">';
				}                                   

				echo "<tr><td class='row1'><B>&nbsp;".$T['Subdomains']."&nbsp;</B></td>";?>

				<td class="row2">&nbsp;<input type="text" name="data[subdomains]" size="5" maxlength="255" value="<? if ($p['subdomains'] != -1) if($data['subdomains']) echo intval($p['subdomains']); else echo '';?>" id="subdomains" onchange="document.getElementById('subdomaincheck').checked = false;">&nbsp;<input type=checkbox id="subdomaincheck" name="data[subdomains]" value="-1" onclick="document.getElementById('subdomains').value = '';" <? if ($p['subdomains'] == -1) echo "checked";?><?if ($resellerdata['subdomains'] != -1) echo " disabled";?>><?=$T['Unlimited'];?></td>

				<?

				echo "<tr><td class='row1'><B>&nbsp;".$T['Pointers']."&nbsp;</B></td>";?>

				<td class="row2">&nbsp;<input type="text" name="data[pointers]" size="5" maxlength="255" value="<? if ($p['pointers'] != -1) if($p['pointers']) echo intval($p['pointers']); else echo '';?>" id="pointers" onchange="document.getElementById('pointercheck').checked = false;">&nbsp;<input type=checkbox id="pointercheck" name="data[pointers]" value="-1" onclick="document.getElementById('pointers').value = '';" <? if ($p['pointers'] == -1) echo "checked";?><?if ($resellerdata['pointers'] != -1) echo " disabled";?>><?=$T['Unlimited'];?></td>

				<?

				echo "<tr><td class='row1'><B>&nbsp;".$T['Databases']."&nbsp;</B></td>";?>

				<td class="row2">&nbsp;<input type="text" name="data[databases]" size="5" maxlength="255" value="<? if ($p['databases'] != -1) if(isset($p['databases'])) echo intval($p['databases']); else echo '';?>" id="databases" onchange="document.getElementById('databasecheck').checked = false;">&nbsp;<input type=checkbox id="databasecheck" name="data[databases]" value="-1" onclick="document.getElementById('databases').value = '';" <? if ($p['databases'] == -1) echo "checked";?><?if ($resellerdata['db'] != -1) echo " disabled";?>><?=$T['Unlimited'];?></td>

				<? 
				if ($cfg['maillist'] == 'mailman') {
				
					echo "<tr><td class='row1'><B>&nbsp;".$T['Mailing Lists']."&nbsp;</B></td>";?>
					<td class="row2">&nbsp;<input type="text" name="data[mailinglists]" size="5" maxlength="255" value="<? if ($p['mailinglists'] != -1) if(isset($p['mailinglists'])) echo intval($p['mailinglists']); else echo '';?>" id="mailinglists" onchange="document.getElementById('mailinglistscheck').checked = false;">&nbsp;<input type=checkbox id="mailinglistscheck" name="data[mailinglists]" value="-1" onclick="document.getElementById('mailinglists').value = '';" <? if ($p['mailinglists'] == -1) echo "checked";?><?if ($resellerdata['mm'] != -1) echo " disabled";?>><?=$T['Unlimited'];?></td>
				
				<? 
				} else {
					echo '<input type=hidden id="mailinglistscheck" name="data[mailinglists]" value="-1">';
				} 

				foreach($sslang as $val) {

					echo "<tr><td class='row1'><B>&nbsp;$val&nbsp;</B></td><td class='row2'>";

					if ($resellerdata['serverside'][$val] == "off") {

						echo "<img src='icon/na.gif'><input type=hidden name=data[serverside][$val] value='na'>";

					} else {

						echo "<input type=checkbox name=data[serverside][$val]>";

					}

					echo "</td></tr>";

				}

				echo "<tr><td class='row1'><B>&nbsp;".$T['Shell Access']."&nbsp;</B></td><td class='row2'>";

				if ($resellerdata['shell'] == "off") {

					echo "<img src='icon/na.gif'>";

				} else {

					echo "<input type=checkbox name=data[shell]>";

				}

				echo "</td></tr>";

			?>

		</table>

		</td>

	</tr>

</table>

<br>

<input type=submit value="<?=$T['Add Package'];?>">

</form>

</div>

